//
//  ZTPanel.m
//  ZHYYTool
//
//  Created by MT-SW-005 on 2021/11/4.
//  Copyright © 2021 MT-SW-005. All rights reserved.
//

#import "ZTPanel.h"

@implementation ZTPanel


/* 选择文件方法 */
+(NSString*)findFile
{
    NSString *path = @"";
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    [panel setMessage:@"Open File"]; //提示信息
    [panel setCanChooseFiles:YES];//是否能选择文件file
    [panel setCanChooseDirectories:YES];//是否能打开文件夹
    [panel setAllowsMultipleSelection:NO];//是否允许多选file
    [panel setCanCreateDirectories:YES]; //是否可以创建文件夹
    [panel setDirectoryURL:[NSURL URLWithString:@"~/Desktop"]]; //设置默认打开的文件夹

    NSInteger finded = [panel runModal]; //获取panel的响应
    if (finded == NSModalResponseOK) {
        path = [panel.URL path];
    }
    return path;
}



/* 保存文件方法 */
+(NSString *)saveFile
{
    NSString *filePath = @"";
    NSSavePanel *savePanel = [NSSavePanel savePanel];
    savePanel.message = @"Save File";
    savePanel.title = @"Save File Panel";
    savePanel.nameFieldStringValue = @"new File";
    savePanel.canCreateDirectories = YES;
    savePanel.canSelectHiddenExtension = YES;
    savePanel.directoryURL = [NSURL URLWithString:@"~/Desktop"];
    
    NSInteger finded = [savePanel runModal];
    if (finded == NSModalResponseOK) {
        filePath = [[savePanel URL] path];
    }
    return filePath;
}
@end
